<template>
  <div class="addProtocol">
    <el-dialog
      title="编辑"
      :visible.sync="readactProtocolDialogShow"
      class="box"
      :before-close="handleClose"
    >
      <el-form :model="redactForm">
        <el-form-item label="ID：" :label-width="formLabelWidth">
          <input v-model="redactForm.resource_id" disabled class="typeInput"/>
        </el-form-item>
        <el-form-item label="分类：" :label-width="formLabelWidth">
          <input v-model="redactForm.catagory" disabled class="typeInput"/>
        </el-form-item>
        <el-form-item label="品牌：" :label-width="formLabelWidth">
          <input v-model="redactForm.brand" disabled class="typeInput"/>
        </el-form-item>
        <el-form-item label="型号：" :label-width="formLabelWidth">
          <input v-model="redactForm.model"  class="typeInput" placeholder="请输入型号"/>
        </el-form-item>
        <el-form-item label="通讯类型：" :label-width="formLabelWidth">
          <el-select v-model="redactForm.type" placeholder="请选择通讯类型">
            <el-option
              v-for="item in paramoptions"
              :key="item.label"
              :label="item.label"
              :value="item.label">
            </el-option>
          </el-select>
          <!--<input v-model="redactForm.type"  class="typeInput" placeholder="请输入通讯类型"/>-->
        </el-form-item>
        <el-form-item label="通讯参数：" :label-width="formLabelWidth">
          <input v-model="redactForm.param"  class="typeInput" placeholder="请输入通讯参数"/>
        </el-form-item>
        <!--<el-form-item label="上传点表：" :label-width="formLabelWidth">-->
        <!--<template  slot-scope="scope">-->
        <!--<div class="grid-content bg-purple">-->
        <!--<el-upload-->
        <!--class="upload-demo"-->
        <!--action=""-->
        <!--:on-preview="handlePreview"-->
        <!--:on-remove="handleRemove"-->
        <!--:http-request="uploadProtocol"-->
        <!--multiple-->
        <!--:limit="1"-->
        <!--:on-exceed="handleExceed">-->
        <!--<el-button style="margin-bottom: 10px; color: #52C2D2;" size="small">点击上传</el-button>-->
        <!--&lt;!&ndash;<div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>&ndash;&gt;-->
        <!--</el-upload>-->
        <!--</div>-->
        <!--</template>-->
        <!--</el-form-item>-->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmRedact()">保 存</el-button>
        <el-button type="info" @click="handleClose()">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'

  export default {
    props: ['userIndex', 'userRow'],
    data() {
      return {
        redactForm: {},
        dialogBack: false,
        formLabelWidth: '85px',
        // 下拉框
        paramoptions: [],
        // 通讯类型获取
        communityType: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'get_commtype'
        },
        // 获取数据接口
        getProtocolData: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'protocol_query',
          id: ''
        },
        // 修改接口
        redactProtocol: {
          access_token: window.localStorage.getItem('access_token'),
          type: 'projects_type_mod',
          data: {
            resource_id: '',
            model: '',
            param: '',
            type: '',
            brand: '',
            catagory: '',
            attris_file: ''
          }
        }
      }
    },
    created() {
      this.readactProtocolDialogShow = true
    },
    mounted() {
      this.formParent()
      this.typeSelect()
    },
    methods: {
      // 下拉获取
      typeSelect() {
        axios.post('/protocol', this.communityType, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.paramoptions = res.data.data
          console.log(res)
        })
          .catch((error) => {
            console.log(error)
          })
      },
      // 子组件传值
      handleClose() {
        const dialogShow = this.dialogBack // 所需要传的值
        this.$emit('giveFalse', dialogShow) // 传值的参数
      },
      // 接受父组件的值
      formParent() {
        console.log(this.userRow)
        console.log(this.userIndex)
        this.getProtocolData.id = this.userRow.resource_id
        axios.post('/protocol', this.getProtocolData, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          console.log(res)
          this.redactForm = res.data.data
        })
          .catch((error) => {
            console.log(error)
          })
      },
      // 确认修改
      confirmRedact() {
        this.redactProtocol.data = this.redactForm
        this.redactProtocol.data.attris_file = ''
        axios.post('/protocol', this.redactProtocol, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          console.log(res)
        })
          .catch((error) => {
            console.log(error)
          })
        this.handleClose()
      }
      // 以下为获取数据方法
      // 获取列表信息
      //      queryData() {
      //        axios.post('/heartbeat', this.submitdata, {
      //          headers: {
      //            'Content-Type': 'application/x-www-form-urlencoded'
      //          }
      //        }).then((res) => {
      //          console.log(res)
      //        })
      //          .catch(function(error) {
      //            console.log(error)
      //          })
      //      }
    }
  }
</script>

<style scoped>
  /*****************第一层弹窗*****************/
  /deep/ .box > .el-dialog{
    width: 540px !important;
    min-height: 350px;
    margin-top: 30vh !important;
    border-radius: 4px;
  }
  /*****************输入框*****************/
  .typeInput{
    width: 425px;
    height: 25px;
    border-radius: 4px;
    border: 1px solid #ccc;
    outline: none;
    text-indent: 10px;
  }
  input::-webkit-input-placeholder{
    color: #C0C4CC;
  }
  /*****************第一层弹窗头部*****************/
  /deep/ .box > .el-dialog > .el-dialog__header{
    width: 540px;
    height: 39px;
    line-height: 43px;
    padding: 0;
    text-indent: 20px;
    font-weight: bolder;
    border-radius: 4px 4px 0 0;
    background-color: #e3e6ee;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn{
    top: 12px;
  }
  /deep/ .box > .el-dialog > .el-dialog__header > .el-dialog__headerbtn > i{
    font-size: 18px;
    font-weight: bolder;
  }
  /*****************第一层弹窗内容*****************/
  /deep/ .box > .el-dialog > .el-dialog__body{
    padding: 0 0 0 10px ;
    margin-top: 15px;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item{
    margin-bottom: 0px;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item > .el-form-item__label{
    color: #69727E;
    padding: 0;
    font-weight: normal;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .el-form-item > .el-form-item__content > .el-input > .el-input__inner{
    width: 240px;
    height: 30px;
    padding: 0 5px;
  }
  /deep/ .box > .el-dialog > .el-dialog__body > .el-form > .borderNone > .el-form-item__content > .el-input > .el-input__inner{
    border: none;
  }
  /*****************第一层弹窗底部*****************/
  /deep/ .box > .el-dialog > .el-dialog__footer{
    border-top: 1px solid #e3e6ee;
    padding: 15px;
  }
  /************下拉框样式************/
  /deep/ .el-input__inner{
    height: 25px;
    width: 425px;
    outline: none;
  }
  /*****************底部按钮*****************/
  /deep/ .dialog-footer{
    padding-top: 8px;
  }
  /deep/ .dialog-footer > .el-button{
    width: 80px;
    height: 30px;
    padding: 0;
  }
</style>
